/**
 * @name 权限
 */
layui.define(['larry', 'form', 'table', ], function(exports) {
    "use strict";
    var $ = layui.$,
        larry = layui.larry,
        form = layui.form,
        table = layui.table;
    var tableIns = table.render({
        elem: '#userList', //指定原始表格元素选择器（推荐id选择器）
        cols: [
            [{
                field: 'userId',
                title: 'ID',
                align: 'center',
            }, {
                field: 'username',
                align: 'center',
                title: '帐号',
            }, {
                field: 'realname',
                align: 'center',
                title: '姓名',
            },{
                field: 'phone',
                align: 'center',
                title: '电话',
            },{
                field: 'email',
                align: 'center',
                title: '邮箱',
            }, {
                field: 'avatar',
                align: 'center',
                title: '头像',
                templet: '#iconTpl',
                
            },{
                field: 'sex',
                align: 'center',
                title: '性别',
                templet: '#sexTpl',
            }, {
                field: 'locked',
                align: 'center',
                title: '状态',
                templet: '#statusTpl',
            }, {
                align: 'center',
                title: '操作',
                toolbar: '#userBar'
            }]
        ], //设置表头
        url: '/backend/system/upms/user/findPagingQuery',
        page: true,
		loading: true,
		limits: [10,30,60,90,150,300],
		limit: 10 //默认采用60
    });
   
    //添加根菜单
    $('#addUser').on('click', function() {
        layer.open({
            type: 2,
            title: '添加根菜单',
            shadeClose: true,
            shade: 0.8,
            area: ['100%', '100%'],
            content: '/backend/system/upms/user/add', //iframe的url
            end: function() {
                tableIns.reload();
            }
        });
    });
    //监听工具条
    table.on('tool(userList)', function(obj) {
        var data = obj.data;
        if (obj.event === 'detail') {
          
        } else if (obj.event === 'del') {
            //删除        
            layer.confirm('真的删除行么', function(index) {
               $.post("/backend/system/upms/user/delectUser",{"userId":data.userId},function(result){
            	   if (result.status == 200) {
                       tableIns.reload();
                   } else {
                       layer.msg(result.msg);
                       tableIns.reload();
                   }
                   layer.close(index);
               });
            });
        } else if (obj.event === 'edit') {
        		//编辑
        		layer.open({
                type: 2,
                title: '添加角色',
                shadeClose: true,
                shade: 0.8,
                area: ['100%', '100%'],
                content: '/backend/system/upms/user/edit?userId='+data.userId, //iframe的url
                end: function() {
                    tableIns.reload();
                }
            });
        }
    });
    
  //监听锁定操作
    form.on('checkbox(status)', function(obj) {
        $.post("/backend/system/upms/user/updataDisableUserId", {
            "userId": this.value
        }, function(result) {
            if (result.status != 200) {
                layer.tips(result.mgs);
                tableIns.reload();
            }
        });
    });
    
    
    exports('mypanel', {});
});